<?php

namespace App\Console\Commands;

use App\Models\GoodsSeckill;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class StockRollback extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:name';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()//库存回退
    {
        $seckillData = GoodsSeckill::whereNotIn('seckill_id', [0])->get()->toArray();

        foreach ($seckillData as $key => $value) {
            if (strtotime($value['created_at']) + 6000 > time()) {//十分钟没有支付，库存回退
                Redis::rpush('goods_id-'.$value['goods_id'],'rollback');
            }
        }
    }
}
